<template>
  <div>
    <input v-model="keywords" placeholder="输入关键字搜索">
    <MyTable :data="filteredRecords">
      <template #header>
        <th>就诊日期</th>
        <th>医生姓名</th>
        <th>诊断结果</th>
        <th>处方信息</th>
        <th>操作</th>
      </template>
      <template #body="{ item }">
        <td>{{ item.date }}</td>
        <td>{{ item.doctor }}</td>
        <td>{{ item.diagnosis }}</td>
        <td>{{ item.prescription }}</td>
        <td @click="showDetail(item)">详情</td>
      </template>
    </MyTable>
    <MyDetail :record="currentRecord" :visible.sync="isshowDetail"></MyDetail>
  </div>
</template>
<script>

import MyDetail from './components/MyDetail.vue';
import MyTable from './components/MyTable.vue';

export default {
  components: {
    MyTable,
    MyDetail
  },
  data() {
    return {
      currentRecord: null,
      isshowDetail: false,
      keywords: '',
      records: [
        {
          date: '2022-01-01',
          doctor: '张三',
          diagnosis: '感冒',
          prescription: '感冒药',
        },
        {
          date: '2022-02-01',
          doctor: '李四',
          diagnosis: '头疼',
          prescription: '止疼药',
        },
        {
          date: '2022-03-01',
          doctor: '王五',
          diagnosis: '腰痛',
          prescription: '止痛贴',
        }
      ]
    }
  },
  computed: {
    filteredRecords() {
      if (!this.keywords) {
        return this.records;
      } else {
        return this.records.filter(record => {
          return Object.values(record).some(value => {
            return value.toString().includes(this.keywords);
          });
        });
      }
    }
  },
  methods: {
    showDetail(record) {
      this.currentRecord = record
      this.isshowDetail = true
    }
  },

}
</script>
<style scoped></style>
